// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Page.cs" company="ecblog.codeplex.com">
//   emrecoskun.net - ibrahimatay.com
// </copyright>
// <summary>
//   The page
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace EcBlog.Models
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    
    // using System.ComponentModel.DataAnnotations.Schema;
    using System.Web.Mvc;

    using EcBlog.Models.Validations;
    using EcBlog.Properties;

    /// <summary>
    /// The page
    /// </summary>
    public sealed class Page
    {
        /// <summary>
        /// Gets or sets the page id.
        /// </summary>
        /// <value>
        /// The page id.
        /// </value>
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public long PageId { get; set; }

        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>
        /// The title.
        /// </value>
        [Required][StringLength(500)]
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the slug.
        /// </summary>
        /// <value>
        /// The slug.
        /// </value>
        [Required, AdminAreaValidation, StringLength(500)]
        [Remote("CheckDuplicateSlug",
           "Page",
           "Admin",
           AdditionalFields = "PageId",
           ErrorMessageResourceName = "CheckDuplicate", ErrorMessageResourceType = typeof(ModelLocalization))]
        public string Slug { get; set; }

        /// <summary>
        /// Gets or sets the content HTML.
        /// </summary>
        /// <value>
        /// The content HTML.
        /// </value>
        [DataType(DataType.Html)] 
        [Column(TypeName = "ntext")]
        [MaxLength]
        public string ContentHtml { get; set; }

        /// <summary>
        /// Gets or sets the layout id.
        /// </summary>
        /// <value>
        /// The layout id.
        /// </value>
        [UIHint("LayoutId")]
        public long LayoutId { get; set; }

        /// <summary>
        /// Gets or sets the layout.
        /// </summary>
        /// <value>
        /// The layout.
        /// </value>
        [ScaffoldColumn(false)] 
        [ForeignKey("LayoutId")]
        public Layout Layout { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is commentable.
        /// </summary>
        /// <value>
        ///     <c>true</c> if this instance is commentable; otherwise, <c>false</c>.
        /// </value>
        public bool IsCommentable { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this instance is publish.
        /// </summary>
        /// <value>
        ///   <c>true</c> if this instance is publish; otherwise, <c>false</c>.
        /// </value>
        public bool IsPublish { get; set; }
          
        /// <summary>
        /// Gets or sets the published.
        /// </summary>
        /// <value>
        /// The published.
        /// </value>
        [DataType(DataType.DateTime)]
        public DateTime Published { get; set; }

        /// <summary>
        /// Gets or sets the created.
        /// </summary>
        /// <value>
        /// The created.
        /// </value>
        [ScaffoldColumn(false)]
        public DateTime Created { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether [show post list].
        /// </summary>
        /// <value>
        ///    <c>true</c> if [show post list]; otherwise, <c>false</c>.
        /// </value>
        public bool ShowPostList { get; set; }

        /// <summary>
        /// Gets or sets the comments.
        /// </summary>
        /// <value>
        /// The comments.
        /// </value>
        [ScaffoldColumn(false)]
        public ICollection<Comment> Comments { get; set; }

        /// <summary>
        /// Gets or sets the tags.
        /// </summary>
        /// <value>
        /// The tags.
        /// </value>
        [ScaffoldColumn(false)]
        public ICollection<Tag> Tags { get; set; }

        /// <summary>
        /// Gets or sets the summary.
        /// </summary>
        /// <value>
        /// The summary.
        /// </value>
        [DataType(DataType.MultilineText)]
        
        [Column(TypeName = "ntext")]
        [MaxLength]
        public string Summary { get; set; }

        /// <summary>
        /// Gets or sets the last modified.
        /// </summary>
        /// <value>
        /// The last modified.
        /// </value>
        [ScaffoldColumn(false)]
        public DateTime LastModified { get; set; }

        /// <summary>
        /// Gets or sets the last modified user.
        /// </summary>
        /// <value>
        /// The last modified user.
        /// </value>
        [StringLength(50)]
        [ScaffoldColumn(false)]
        public string LastModifiedUser { get; set; }
    }
}